<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑模型</title>
    <link rel="stylesheet" href="__COMMON__/dtree/dtree.css">
    <link rel="stylesheet" href="__COMMON__/dtree/font/dtreefont.css">
    <link rel="stylesheet" href="__COMMON__/css/simple.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>

<form class="layui-form" action="" style="padding: 10px">
    <input type="hidden" name="model_id" value="{$info['model_id']}"/>
    <div class="layui-form-item">
        <label class="layui-form-label"><em style="color: red">*</em> 模型名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" required  lay-verify="required" autocomplete="off" class="layui-input" id="name" value="{$info['name']}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><em style="color: red">*</em> 模型标识</label>
        <div class="layui-input-inline">
            <input type="text" name="uuid" required lay-verify="required" autocomplete="off" class="layui-input" id="uuid" value="{$info['uuid']}">
        </div>
        <div class="layui-form-mid layui-word-aux" style="margin-top: -10px">建议由小写字母、数字组成，<br/>因为部份Unix系统无法识别中文文件。</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><em style="color: red">*</em> 栏目页模板</label>
        <div class="layui-input-block">
            <input type="text" name="channel_tpl" required  lay-verify="required" autocomplete="off" class="layui-input" id="channel_tpl" placeholder="必须以channel_开头" value="{$info['channel_tpl']}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><em style="color: red">*</em> 列表页模板</label>
        <div class="layui-input-block">
            <input type="text" name="list_tpl" required  lay-verify="required" autocomplete="off" class="layui-input" id="list_tpl" placeholder="必须以list_开头" value="{$info['list_tpl']}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><em style="color: red">*</em> 详情页模板</label>
        <div class="layui-input-block">
            <input type="text" name="show_tpl" required  lay-verify="required" autocomplete="off" class="layui-input" id="show_tpl" placeholder="必须以show_开头" value="{$info['show_tpl']}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题重复</label>
        <div class="layui-input-block">
            <input type="radio" name="is_repeat_title" value="1" title="允许" {if $info['is_repeat_title'] eq 1}checked{/if}>
            <input type="radio" name="is_repeat_title" value="2" title="不允许" {if $info['is_repeat_title'] eq 2}checked{/if}>
        </div>
    </div>

    <div class="layui-form-item" style="margin-top: 40px">
        <div class="layui-input-block">
            <button type="button" class="am-btn am-btn-success am-btn-sm" lay-submit lay-filter="subForm">立即提交</button>
            <button type="reset" class="am-btn am-btn-default am-btn-sm" >重置</button>
        </div>
    </div>
</form>

<script src="__COMMON__/jquery.min.js"></script>
<script src="__STATIC__/layui/layui.js"></script>
<script>

    layui.use(['form', 'layer'], function() {
        var form = layui.form;
        var dtree = layui.dtree, layer = layui.layer;

        // 监听提交
        form.on('submit(subForm)', function(data) {

            $.post('{:url("modelx/edit")}', data.field, function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg);

                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.initTable();
                    }, 800);
                } else {
                    layer.msg(res.msg);
                }
            }, 'json');
            return false;
        });
    });

    $(function () {
        $("#name").bind("input propertychange", function(event){
            $.post('{:url("modelx/getPinyin")}', {name: $("#name").val()}, function (res) {
                if (res.code == 0) {
                    $("#uuid").val(res.data);
                    $("#channel_tpl").val('channel_' + res.data + '.html');
                    $("#list_tpl").val('list_' + res.data + '.html');
                    $("#show_tpl").val('show_' + res.data + '.html');
                }
            }, 'json');
        });

        $("#uuid").bind("input propertychange", function(event){

            var uuid = $("#uuid").val();
            if (uuid) {
                $("#channel_tpl").val('channel_' + uuid + '.html');
                $("#list_tpl").val('list_' + uuid + '.html');
                $("#show_tpl").val('show_' + uuid + '.html');
            } else {
                $("#channel_tpl").val('');
                $("#list_tpl").val('');
                $("#show_tpl").val('');
            }
        });
    });
</script>
</body>
</html>